export const column = [
    {
        label: 'ID',
        name: 'id',
    },
    {
        label: '名称',
        name: 'name',
    },
    {
        title: '操作',
        name: 'action',
        width: '260',
        buttons: [],
    },
]

export const config = [
    {
        name: 'name',
        type: 'input',
        placeholder: '名称',
        label: '名称',
        required: true,
    },
    {
        name: 'value',
        type: 'cascader',
        placeholder: '选择模型',
        label: '选择模型',
        required: true,
        options: [],
        multiple: true,
        filterable: true,
    },
]

export const formatData = (data) => {
    const result = []
    data.forEach((item) => {
        if (item.modeltype && item.trouble && item.typecode && item.warncode) {
            let modelType = result.find((item1) => item1.value === item.modeltype)
            if (!modelType) {
                modelType = {
                    label: item.modeltype,
                    value: item.modeltype,
                    children: [],
                }
                result.push(modelType)
            }
            let troubleType = modelType.children.find((item2) => item2.value === item.typecode)
            if (!troubleType) {
                troubleType = {
                    label: item.trouble,
                    value: item.typecode,
                    children: [],
                }
                modelType.children.push(troubleType)
            }
            const warnCode = {
                label: `${item.description} `,
                value: item,
            }
            troubleType.children.push(warnCode)
        }
    })
    return result
}
